<style>
.weui_btn {
	border-radius: 1rem;
}
.fui-picturew .item .image {
	width:100%;
    height:5.6rem;
}
.fui-picturew .item img {
    width: 100%;
    height: 100%;
}
.fui-picturew .item .image .input {
    position: absolute;
    top: 0;
    left: 0;
}
.pagination {
	display:inline-block;
	padding-left:0;
	margin:0.3rem 0;
	border-radius:4px
}
.fui-tab-scroll .item {margin-right:0.2rem}
.fui-tab.fui-tab-danger a.active {
    border-color: #5bc0de;
}
.fui-header:after {
	height: 0;
	border-bottom: 0 solid #D9D9D9;
}
.fui-tab:after {
    height: 0;
	border-bottom: 0 solid #D9D9D9;
}
</style>
<div class="fui-page" style="position:static;min-height:22rem;border-radius:0.2rem;background:#fff">
	<div class="fui-header" style="background:#fff">
			<div class="fui-header-input" style="margin-top:0.4rem">
					<div class="searchbar searchbar-active" style="margin-left:0.5rem">
						<div class="search-input" style="margin-right:2.5rem">
							<i class="icon jinyunicon icon-search" style="font-size: 0.8rem;"></i>
							<input type="search" id="search" ng-model="pagedata.params.title" placeholder="输入名称..." value="">
						</div>
					</div>
			</div>
			<div class="fui-header-right" style="padding-right:0.4rem">
				<a href="javascript:;" ng-click="pagedata.params.page=1;getmodal(modal,pagedata.op,made_query(pagedata.params))" style="padding:0 0.2rem"> 搜索</a>
			</div>
	</div>
	<div class="fui-content" style="background:#fff;padding:0 0.5rem 2.5rem 0.5rem;border-radius:0.2rem">
				<div class="fui-tab-scroll" style="height:2rem">
					<div ng-repeat="(key,item) in pagedata.content_types" ng-class="{'item':1,'active':pagedata.params.type == key}" style="line-height:1.8rem;padding: 0.1rem 0.6rem;" ng-click="pagedata.params.type=key;tool.get_list('jy_scrm/filelist/list/',true)">{{item}}</div>
				</div>
				<div class="fui-tab fui-tab-danger" style="margin-bottom:0.3rem;border-radius:0.2rem">
					<a ng-repeat="group in pagedata.groups[pagedata.params.type]" ng-class="{'external active':pagedata.params.group_id==group.id}" href="javascript:;" ng-click="pagedata.params.group_id=group.id;tool.get_list('jy_scrm/filelist/list/group_id='+group.id,true)">{{group.title}}</a>
				</div>
				<div ng-if="pagedata.params.type=='text' && pagedata.list.length>0" class="fui-picturew row-3" style="padding:0.3rem;">
					<div ng-repeat="item in pagedata.list" class="item" style="padding: 5px;">
						<div class="title" style="color:#999;font-size:0.65rem;padding:0.2rem;border-radius:0.2rem;background:#f2f2f2" ng-click="pagedata.selectindex=$index">
							<input type="checkbox" class="input fui fui-checkbox fui-checkbox-danger verify-checkbox" ng-checked="pagedata.selectindex==$index">
							{{item.content}}
						</div>
						
					</div>
				</div>
				<div ng-if="(pagedata.params.type=='image' || pagedata.params.type=='news' || pagedata.params.type=='miniprogram') && pagedata.list.length>0" class="fui-picturew row-3" style="padding:0.3rem;">
					<div ng-repeat="item in pagedata.list" class="item" style="padding: 5px;">
						<div class="image" ng-click="pagedata.selectindex=$index">
							<input type="checkbox" class="input fui fui-checkbox fui-checkbox-danger verify-checkbox" ng-checked="pagedata.selectindex==$index">
							<img ng-src="{{tomedia(item.image) || '../core/resource/images/nopic.jpg'}}">
							<div class="title" style="">{{item.title}}</div>
						</div>
						
					</div>
				</div>
				<div ng-if="pagedata.params.type=='audio' && pagedata.list.length>0" class="fui-picturew row-3" style="padding:0.3rem;">
					<a ng-repeat="item in pagedata.list" class="item"  style="padding: 5px;">
						<div class="image" ng-click="pagedata.selectindex=$index">
							<input type="checkbox" class="input fui fui-checkbox fui-checkbox-danger verify-checkbox" ng-checked="pagedata.selectindex==$index">
							<i onclick="$(this).toggleClass('fa-play fa-stop');play_audio($(this).next())" class="fa fa-play"></i><audio style="display:none;" src="{{tomedia(item.file)}}" loop="loop"></audio>
							<div class="title" style="">{{item.title}}</div>
						</div>
					</a>
				</div>
				<div ng-if="pagedata.params.type=='video' && pagedata.list.length>0" class="fui-picturew row-3" style="padding:0.3rem;">
					<a ng-repeat="item in pagedata.list" class="item"  style="padding: 5px;">
						<div class="image" ng-click="pagedata.selectindex=$index" style="height:100px">
							<input type="checkbox" class="input fui fui-checkbox fui-checkbox-danger verify-checkbox" style="z-index:10000" ng-checked="pagedata.selectindex==$index">
							<video src="{{tomedia(item.file)}}" poster="{{tomedia(item.thumb)}}" style="width:100%" height="100" controls="controls"></video>
							<div class="title">{{item.title}}</div>
						</div>
					</a>
				</div>
				<div class="content-empty" ng-show="!pagedata.list || pagedata.list.length == 0 ">
					  <i class="icon jinyunicon icon-cry" style="width: 6rem;margin-bottom: 0.5rem;"></i><br/><p style="color: #999;font-size: .75rem">还没有任何内容</p>
				</div>
	</div>
	<div class="fui-navbar">
		<div ng-click="pagedata.send_file()" class="nav-item btn btn-info">发送</div>
	</div>
</div>
<script>
scope.tool.get_list('jy_scrm/filelist/list/',true);
scope.pagedata.scroll_bottom=function(){
	scope.tool.get_list('jy_scrm/filelist/list/');
}
</script>
<script>
scope.pagedata.send_file=function(){
	var item = scope.pagedata.list[scope.pagedata.selectindex]
	if(!item || !item.id){
		scope.message('请选择内容！');
		return false;
	}
	if(scope.pagedata.params.type=='text'){
		wx.invoke('sendChatMessage', {
			msgtype:'text',
			text: {
				content:item.content,
			}
		}, function(res) {
			if (res.err_msg == 'sendChatMessage:ok') {
				//发送成功
			}else if (res.err_msg == 'sendChatMessage:fail_nopermission') {
				scope.message('该应用没有开启客服联系权限，不能推送消息！');
			}else{
				scope.message(res.err_msg);
			}
		});
	}
	if(scope.pagedata.params.type=='image'){
		wx.invoke('sendChatMessage', {
			msgtype:'image',
			image: {
				mediaid:item.appmedia_id,
			}
		}, function(res) {
			if (res.err_msg == 'sendChatMessage:ok') {
				//发送成功
				scope.message('发送成功！');
			}else{
				scope.message('发送失败：'+res.err_msg);
			}
		});
	}
	if(scope.pagedata.params.type=='audio'){
		wx.invoke('sendChatMessage', {
			msgtype:'audio',
			video: {
				mediaid:item.appmedia_id,
			},
		}, function(res) {
			alert(res.err_msg);
			if (res.err_msg == 'sendChatMessage:ok') {
				//发送成功
			}
		});
	}
	if(scope.pagedata.params.type=='video'){
		wx.invoke('sendChatMessage', {
			msgtype:'video',
			video: {
				mediaid:item.appmedia_id,
			},
		}, function(res) {
			alert(res.err_msg);
			if (res.err_msg == 'sendChatMessage:ok') {
				//发送成功
			}
		});
	}
	if(scope.pagedata.params.type=='file'){
		wx.invoke('sendChatMessage', {
			msgtype:'file',
			file: {
				mediaid:item.appmedia_id,
			},
		}, function(res) {
			if (res.err_msg == 'sendChatMessage:ok') {
				//发送成功
			}
		});
	}
	if(scope.pagedata.params.type=='news'){
		wx.invoke('sendChatMessage', {
			msgtype:'news',
			news: {
				link: item.h5url, //H5消息页面url 必填
				title: item.title, //H5消息标题
				desc: item.desc, //H5消息摘要
				imgUrl: item.image, //H5消息封面图片URL
			},
		}, function(res) {
			if (res.err_msg == 'sendChatMessage:ok') {
				//发送成功
			}else{
				//console.log(res);
				res.errMsg=res.errMsg?res.errMsg:res.err_msg
				scope.message('发送失败！'+res.errMsg);
			}
		});
	}
}
</script>